const TokenKey = 'xw-user-token';
const MenuKey = 'xw-user-menu';
const UserKey = 'xw-user-info';

export function clean() {
  sessionStorage.removeItem(TokenKey);
  sessionStorage.removeItem(UserKey);
  sessionStorage.removeItem(MenuKey);
}

export function getToken() {
  return sessionStorage.getItem(TokenKey)
}

export function setToken(token) {
  sessionStorage.setItem(TokenKey, token)
}

export function removeToken() {
  sessionStorage.removeItem(TokenKey)
}


export function setMenus(menus) {
  sessionStorage.setItem(MenuKey, JSON.stringify(menus));
}

export function getMenus() {
  let menus = sessionStorage.getItem(MenuKey);
  if (menus && menus != 'undefined') {
    menus = JSON.parse(menus);
  }else{
    menus = null;
  }
  return menus;
}

export function removeMenus() {
  sessionStorage.removeItem(MenuKey)
}

export function setCurrUser(userInfo) {
  sessionStorage.setItem(UserKey, JSON.stringify(userInfo))

}

export function getCurrUser() {
  let userInfo = sessionStorage.getItem(UserKey);
  if (userInfo) {
    userInfo = JSON.parse(userInfo);
  }
  return userInfo;
}

export function removeCurrUser() {
  sessionStorage.removeItem(UserKey)
}
